Array.prototype.swap = function(orignIndex,targetIndex) {
    let temp = this[orignIndex]
    this[orignIndex] = this[targetIndex]
    this[targetIndex] = temp
}
function insert(arr){
    for(let i = 0;i < arr.length - 1;i++) {
        for(let j  = i + 1; j > 0; j--) {
            if(arr[j] < arr[j - 1]) {
                arr.swap(j,j-1)
            } else {
                break
            }
        }
    }
    return arr
}
console.log(insert([1,2,3,4,3,4,1,2]));